package com.yjt.sousou.create;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.sousou.R;
import com.yjt.sousou.create.entity.FaultTypeSelect;

import java.util.List;

/**
 * 作者：83734
 * 时间：2018/12/2
 * 描述：选择完之后的故障类型
 */
public class FaultTypeAdapter extends BaseQuickAdapter<FaultTypeSelect,BaseViewHolder> {
    public FaultTypeAdapter(int layoutResId, @Nullable List<FaultTypeSelect> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final FaultTypeSelect item) {
        helper.setText(R.id.tv_fault_type,item.getGzlx_name());
        helper.setText(R.id.tv_num,item.getGzlx_sum());
        final TextView tv_num = helper.getView(R.id.tv_num);
        final int[] num = {1};
        helper.getView(R.id.iv_minus).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num[0]--;
                if(num[0]<1){
                    num[0] = 1;
                    getData().remove(item);
                    notifyDataSetChanged();
                }else {
                    tv_num.setText(String.valueOf(num[0]));
                    getData().get(helper.getAdapterPosition()).setGzlx_sum(String.valueOf(num[0]));
                }
            }
        });
        helper.getView(R.id.iv_plus).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                num[0]++;
                tv_num.setText(String.valueOf(num[0]));
                getData().get(helper.getAdapterPosition()).setGzlx_sum(String.valueOf(num[0]));
            }
        });
    }
}
